﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace ShellAnywhere.Model
{
	public class Open : Target, IVerb
	{
		#region ctors
		public Open() : base() { Name = "open"; }
		#endregion ctors

		#region props
		#endregion props

		#region methods
		public bool Execute(ITarget target, params IParam[] paramz)
		{
			bool result = false;
			string filename = target.Path;
			string arguments = target.Arguments;
			if (File.Exists(filename))
			{
				if (paramz != null)
				{
					foreach (IParam param in paramz)
						arguments += param.Name + " ";
				}
				try
				{
					ProcessStartInfo psi = new ProcessStartInfo(filename, arguments);
					Process process = Process.Start(psi);
					result = (process != null) ? process.Responding : true;
				}
				catch (Exception ex)
				{
					throw ex;
				}
			}
			return result;
		}
		#endregion methods

		#region fields
		#endregion fields
	}
}
